package com.server.questionbank.snframe.mapper.QuestionBank;


import com.server.questionbank.snframe.domain.User.UansQueRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UansQueRecordMapper {
    /**
     * 新增作答记录
     * @param uansQueRecord
     * @return
     */
    @Insert("INSERT INTO uans_que_record(record_id, rec_id, last_save_time, user_answer, " +
            "mark_time, mark_man, full_mark, score, answer_comment) " +
            "VALUES(#{recordId}, #{recId}, #{lastSaveTime}, #{userAnswer}, " +
            "#{markTime}, #{markMan}, #{fullMark}, #{score}, #{answerComment})")
    int addAnswerRecords(UansQueRecord uansQueRecord);

    /**
     * 更新用户答题记录
     * @param uansQueRecord 用户答题记录实体
     * @return 更新结果（影响的行数）
     */

    @Update("UPDATE uans_que_record SET " +
            "last_save_time = #{lastSaveTime}, " +
            "user_answer = #{userAnswer}, " +
            "mark_time = #{markTime}, " +
            "mark_man = #{markMan}, " +
            "full_mark = #{fullMark}, " +
            "score = #{score}, " +
            "answer_comment = #{answerComment} " +
            "WHERE record_id = #{recordId} AND rec_id = #{recId}")
    int updateUserAnswerRecord(UansQueRecord uansQueRecord);

    /**
     * 根据记录ID和问题ID获取用户答题记录
     * @param recordId 答题记录ID
     * @param recId 问题ID
     * @return 用户答题记录
     */
    @Select("SELECT * FROM uans_que_record WHERE record_id = #{recordId} AND rec_id = #{recId}")
    List<UansQueRecord> getUserAnswerRecord(@Param("recordId") Long recordId, @Param("recId") Long recId);;

}
